package com.mofang.powerdekorhelper.activity.login;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.base.MvpActivity;
import com.mofang.powerdekorhelper.model.ResultMessage3;
import com.mofang.powerdekorhelper.persenter.ResetPassWordPresenter;
import com.mofang.powerdekorhelper.utils.T;
import com.mofang.powerdekorhelper.view.ResetPassWordView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by luofei on 2016/8/1 0001.
 */

// 该接口报错 500
public class ResetPassWordActivity extends MvpActivity<ResetPassWordView, ResetPassWordPresenter> implements ResetPassWordView {

    @BindView(R.id.reset_password_pw_edit)
    EditText pwEdit;

    String account;

    @Override
    public void initView() {
        inflateLayout(R.layout.activity_reset_password_layout);
    }

    @Override
    public void initData() {
        account = getIntent().getStringExtra("Account");
    }

    @Override
    public ResetPassWordPresenter initPresenter() {
        return new ResetPassWordPresenter();
    }

    @OnClick({R.id.reset_password_back_imv, R.id.reset_password_commit_btn})
    void OnClick(View v) {

        String passWord = pwEdit.getText().toString();
        switch (v.getId()) {
            case R.id.reset_password_back_imv:
                finish();
                break;

            case R.id.reset_password_commit_btn:
                if (!TextUtils.isEmpty(passWord)) {
                    if (passWord.length() >= 6) {
                        if (!account.equals("")) {
                            presenter.getResetPassWord(account, passWord);
                        }
                    } else {
                        toast(R.string.pwd_format_error);
                    }
                } else {

                    toast(R.string.pwd_notbe_null);
                }
                break;
        }
    }

    @Override
    public void setResetPassWord(ResultMessage3 resetPassword) {

        if (resetPassword.getCode().equals("0") && resetPassword.isResult()) {
            toast("提交成功");
            toActivity(this, LoginActivity.class);
            this.finish();
        } else {
            toast("提交失败");
        }
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void toast(CharSequence s) {
        T.showShort(this, s);
    }

    @Override
    public void toast(int id) {
        T.showShort(this, getResources().getString(id));
    }

    @Override
    public void showNullLayout() {

    }

    @Override
    public void hideNullLayout() {

    }

    @Override
    public void showErrorLayout(View.OnClickListener listener) {

    }

    @Override
    public void hideErrorLayout() {

    }

    @Override
    public void onError(String errorInfo) {
        toast(errorInfo);
    }
}
